package com.briup.jz.service.impl;

import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.AccountSystemExample;
import com.briup.jz.dao.AccountSystemMapper;
import com.briup.jz.service.IAccountSystemService;
import com.briup.jz.utils.CustomerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AccountSystemImpl implements IAccountSystemService {
    @Autowired
    private AccountSystemMapper accountSystemMapper;
    @Override
    public void save(AccountSystem accountSystem) throws CustomerException {
        if (accountSystem.getId()==null){
            accountSystem.setTransferTime(new Date().getTime());
            accountSystemMapper.insert(accountSystem);
        }else {
            AccountSystemExample example =new AccountSystemExample();
            example.createCriteria().andIdEqualTo(accountSystem.getId());
            accountSystem.setTransferTime(new Date().getTime());
            accountSystemMapper.updateByExample(accountSystem,example);
        }
    }

    @Override
    public AccountSystem query(Long id) {
//        根据主键id 查询信息
        AccountSystem accountSystem = accountSystemMapper.selectByPrimaryKey(id);
        return accountSystem;
    }

    @Override
    public void deleteById(Long id) throws CustomerException {
        AccountSystem accountSystem=accountSystemMapper.selectByPrimaryKey(id);
        if (accountSystem.getId()==null){
            throw  new CustomerException("这条系统信息不存在");
        }
        accountSystemMapper.deleteByPrimaryKey(id);
    }
}
